﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Outpatient.Migrations
{
    /// <inheritdoc />
    public partial class modify_OtpSchdType : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "OtpSchdType",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OtpSchdTypeCodg = table.Column<string>(type: "text", nullable: false),
                    OtpSchdTypeName = table.Column<string>(type: "text", nullable: false),
                    RgstWayCode = table.Column<string>(type: "text", nullable: false),
                    RgstWayName = table.Column<string>(type: "text", nullable: false),
                    OrdrWayCode = table.Column<string>(type: "text", nullable: true),
                    OrdrWayName = table.Column<string>(type: "text", nullable: true),
                    DefFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpSchdType", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "OtpSchdPlan",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OtpSchdTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    OtpRgstTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    DeptCodg = table.Column<string>(type: "text", nullable: false),
                    DeptName = table.Column<string>(type: "text", nullable: false),
                    DrCodg = table.Column<string>(type: "text", nullable: true),
                    DrName = table.Column<string>(type: "text", nullable: true),
                    DrProfttlCode = table.Column<string>(type: "text", nullable: true),
                    DrProfttlName = table.Column<string>(type: "text", nullable: true),
                    Begndt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Enddt = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    FollupFlag = table.Column<bool>(type: "boolean", nullable: false),
                    MedrecFlag = table.Column<bool>(type: "boolean", nullable: false),
                    SignFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TrgFlag = table.Column<bool>(type: "boolean", nullable: false),
                    LastExeTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    ValiFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpSchdPlan", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtpSchdPlan_OtpSchdType_OtpSchdTypeId",
                        column: x => x.OtpSchdTypeId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpSchdType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "OtpSchdPeriod",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OtpSchdPlanId = table.Column<Guid>(type: "uuid", nullable: false),
                    Week = table.Column<int>(type: "integer", nullable: false),
                    OtpPeriod = table.Column<int>(type: "integer", nullable: false),
                    AmPeriodCnt = table.Column<int>(type: "integer", nullable: false),
                    PmPeriodCnt = table.Column<int>(type: "integer", nullable: false),
                    EvPeriodCnt = table.Column<int>(type: "integer", nullable: false),
                    OtpConsultRmId = table.Column<Guid>(type: "uuid", nullable: true),
                    TimedivnFlag = table.Column<bool>(type: "boolean", nullable: false),
                    AmBegntime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    AmEndtime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    PmBegntime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    PmEndtime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpSchdPeriod", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtpSchdPeriod_OtpSchdPlan_OtpSchdPlanId",
                        column: x => x.OtpSchdPlanId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpSchdPlan",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "OtpSchdRec",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OtpSchdPlanId = table.Column<Guid>(type: "uuid", nullable: false),
                    OtpSchdPeriodId = table.Column<Guid>(type: "uuid", nullable: false),
                    SchdDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    SchdWeek = table.Column<int>(type: "integer", nullable: false),
                    DeptCodg = table.Column<string>(type: "text", nullable: false),
                    DeptName = table.Column<string>(type: "text", nullable: false),
                    DrCodg = table.Column<string>(type: "text", nullable: true),
                    DrName = table.Column<string>(type: "text", nullable: true),
                    DrProfttlCode = table.Column<string>(type: "text", nullable: true),
                    DrProfttlName = table.Column<string>(type: "text", nullable: true),
                    Amt = table.Column<decimal>(type: "numeric", nullable: false),
                    SchdStas = table.Column<int>(type: "integer", nullable: false),
                    OtpRgstTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    Total = table.Column<int>(type: "integer", nullable: false),
                    OverCnt = table.Column<int>(type: "integer", nullable: false),
                    FollupFlag = table.Column<bool>(type: "boolean", nullable: false),
                    MedrecFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TrgFlag = table.Column<bool>(type: "boolean", nullable: false),
                    SignFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpSchdRec", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtpSchdRec_OtpSchdPeriod_OtpSchdPeriodId",
                        column: x => x.OtpSchdPeriodId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpSchdPeriod",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_OtpSchdRec_OtpSchdPlan_OtpSchdPlanId",
                        column: x => x.OtpSchdPlanId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpSchdPlan",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "OtpSchdRecDetl",
                schema: "Outpatient",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    OtpSchdRecId = table.Column<Guid>(type: "uuid", nullable: false),
                    SchdDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    SchdBegntime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    SchdEndtime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Total = table.Column<int>(type: "integer", nullable: false),
                    OverCnt = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtpSchdRecDetl", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtpSchdRecDetl_OtpSchdRec_OtpSchdRecId",
                        column: x => x.OtpSchdRecId,
                        principalSchema: "Outpatient",
                        principalTable: "OtpSchdRec",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_OtpSchdPeriod_OtpSchdPlanId",
                schema: "Outpatient",
                table: "OtpSchdPeriod",
                column: "OtpSchdPlanId");

            migrationBuilder.CreateIndex(
                name: "IX_OtpSchdPlan_OtpSchdTypeId",
                schema: "Outpatient",
                table: "OtpSchdPlan",
                column: "OtpSchdTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_OtpSchdRec_OtpSchdPeriodId",
                schema: "Outpatient",
                table: "OtpSchdRec",
                column: "OtpSchdPeriodId");

            migrationBuilder.CreateIndex(
                name: "IX_OtpSchdRec_OtpSchdPlanId",
                schema: "Outpatient",
                table: "OtpSchdRec",
                column: "OtpSchdPlanId");

            migrationBuilder.CreateIndex(
                name: "IX_OtpSchdRecDetl_OtpSchdRecId",
                schema: "Outpatient",
                table: "OtpSchdRecDetl",
                column: "OtpSchdRecId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "OtpSchdRecDetl",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpSchdRec",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpSchdPeriod",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpSchdPlan",
                schema: "Outpatient");

            migrationBuilder.DropTable(
                name: "OtpSchdType",
                schema: "Outpatient");
        }
    }
}
